#!/usr/bin/env python
# encoding: utf-8
import pika
import time

credentials = pika.PlainCredentials("guest", "guest")
conn_params = pika.ConnectionParameters("localhost",credentials=credentials)
conn_broker = pika.BlockingConnection(conn_params)
channel = conn_broker.channel()

channel.exchange_declare(exchange="exchange", 
                         exchange_type="direct",
                         passive=False,
                         durable=False,
                         auto_delete=False)

channel.queue_declare(queue="auto_delete_queue",auto_delete=True) 

channel.queue_bind(queue="auto_delete_queue", 
                   exchange="exchange",
                   routing_key="hola")

channel.basic_publish(body="quit",
                      exchange="exchange",
                      routing_key="hola")

'''
def callback(channel, method, header, body):
    channel.basic_ack(delivery_tag=method.delivery_tag) 
    if body == "quit":
        print body
        channel.basic_cancel(consumer_tag="hello-consumer")
        channel.stop_consuming()
    else:
        print body
    return

time.sleep(10)
channel.basic_consume(callback,queue="auto_delete_queue",consumer_tag="hello-consumer")
channel.start_consuming()
'''
time.sleep(10)
method,properties,body = channel.basic_get(queue="auto_delete_queue",no_ack=True)
print body

